package com.fang.thread;


import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @Description
 * @Author Bernie_fang
 * @Date 2023/1/14 11:44
 **/
public class Example3 implements Callable<String> {

    @Override
    public String call() {
        for (int i = 0; i < 1000; i++) {
            System.out.println("2现在是：" + i);
        }
        return "这里是callable";
    }

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        FutureTask task = new FutureTask(new Example3());
        Thread thread = new Thread(task);
        thread.start();
//        System.out.println(task.get());// 使用task.get()获取返回的方法时，线程会阻塞到方法结束
        for (int i = 0; i < 1000; i++) {
            System.out.println("主线程：" + i);
        }
    }

}